package cn.iocoder.yudao.module.biz.dal.mysql.staff;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.biz.dal.dataobject.staff.BizStaffDO;
import cn.iocoder.yudao.module.biz.dal.dataobject.staffPost.BizStaffPostDO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CustomBizStaffMapper extends BaseMapperX<BizStaffDO> {
    String querySql = "select bs.*, bsp.post_name as postName, sdd.label as sexLabel, bsd.staff_dept_name from biz_staff bs left join biz_staff_post bsp on bs.post = bsp.id " +
            "left join system_dict_data sdd on sdd.dict_type='system_user_sex' and bs.sex = sdd.value " +
            "left join biz_staff_dept bsd on bsd.id = bs.staff_dept_id ${ew.customSqlSegment} ";

    /**
     * 分页查询，不支持条件查询
     */
    @Select(querySql)
    List<BizStaffDO> list(Page page, @Param(Constants.WRAPPER) Wrapper queryWrapper);

    /**
     * 分页查询，不支持条件查询
     */
    @Select(querySql)
    List<BizStaffDO> list(@Param(Constants.WRAPPER) Wrapper queryWrapper);

    /**
     * 分页查询，支持Mybatis Plus条件查询
     */
    @Select(querySql)
    PageResult<BizStaffDO> pageList(PageParam pageParam, @Param(Constants.WRAPPER) Wrapper queryWrapper);


    /**
     * 基础查询，注意是查询一条，需控制查询条件
     */
    @Select(querySql)
    BizStaffDO findOne(@Param(Constants.WRAPPER) Wrapper queryWrapper);

    String countSql = "select count(bs.id) from biz_staff bs left join biz_staff_post bsp on bs.post = bsp.id " +
            "left join system_dict_data sdd on sdd.dict_type='system_user_sex' and bs.sex = sdd.value ${ew.customSqlSegment} ";

    /**
     * 关联查询时获取数据数量
     * @param queryWrapper
     * @return
     */
    @Select(countSql)
    Long pageCount(@Param(Constants.WRAPPER) Wrapper queryWrapper);
}
